﻿

//初始化
if (typeof ($) != "undefined") {
    var fun = getPar1("fun");
    $(document).ready(function () {

    });

    if (fun == "view" || fun == "edit")
    {
        GetEmpNameByEmpID(instance[0].EmployeeID);
        GetEmpcodeByEmpID(instance[0].EmployeeID);
    }

    //debugger;
    if (fun == "view") {
        parent.document.getElementById("yui-gen7-button").style.display = "none";
        $("div input").attr("disabled", true).css("background", "whitesmoke");
        $("div select").attr("disabled", true).css("background", "whitesmoke");
        $("div button").hide();
    }
}


//选择员工
var employeeId;
var ValueChanged = function () {
    employeeId = $("#empId").val();
}

var TextChanged = function () {
    var employeeName = $("#txtempId").val();
    if (employeeId == "" || employeeId == "undefined") {
        return;
    }
    if (employeeName == "" || employeeName == "undefined") {
        return;
    }
    //debugger
    $("input[name='txtEmployeeID']").last().val(employeeName);
    $("input[name='EmployeeID']").last().val(employeeId);
    GetEmpcodeByEmpID(employeeId);
}

//获取员工编号
function GetEmpcodeByEmpID(empId) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");

        for (var o in list.rows) {
            var t = list.rows[o].EmployeeCode;
            if (typeof (t) != "undefined") {
                $("input[name='EmployeeCode']").last().val(t);
            }
        }

    });
}

//获取员工姓名
function GetEmpNameByEmpID(empId) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=V_hrEmployee&condition=ID='" + empId + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");

        for (var o in list.rows) {
            var t = list.rows[o].CName;
            if (typeof (t) != "undefined") {
                $("input[name='txtEmployeeID']").last().val(t);
            }
        }

    });
}

var fnCheckData = function () {
    try {
        if ($("#txtEmployeeID").val() == "") {
            return "员工姓名不能为空23！";
        }
        if ($("#EmployeeCode").val() == "") {
            return "员工编号不能为空qq！";
        }
        if ($("#FixedInsurance").val() == "") {
            $("#FixedInsurance").focus();
            return "固定保险金额不能为空！";
        }
        if ($("#WageRate").val() == "") {
            $("#WageRate").focus();
            return "占基本薪资比例不能为空！";
        }

        if ($("#FixedInsurance").val().length > 8) {
            $("#FixedInsurance").focus();
            return "固定保险金额最多输入8位数字！";
        }
        if ($("#WageRate").val().length > 8) {
            $("#WageRate").focus();
            return "占基本薪资比例最多输入8位数字！";
        }

        var reg = /^\d+(\.\d+)?$/;
        if (reg.test($("#FixedInsurance").val()) == false) {
            $("#FixedInsurance").focus();
            return "固定保险金额需要输入非负数字!";
        }
        if (reg.test($("#WageRate").val()) == false) {
            $("#WageRate").focus();
            return "占基本薪资比例需要输入非负数字!";
        }
    }
    catch (e)
     { }
}

